//
//  Departure.m
//  TrainTrack
//
//  Created by Philip Bruce on 4/10/08.
//  Copyright 2008 Den Falske Zebra. All rights reserved.
//

#import "Departure.h"


@implementation Departure

@synthesize station;
@synthesize line;
@synthesize direction;
@synthesize minute;
@synthesize earliest_departure;
@synthesize latest_departure;
@synthesize weekday;
@synthesize valid_at_time;

-(Departure *)initByCloning:(Departure *)dep {
	Departure *departure = [[Departure alloc] init];
	departure.station = dep.station;
	departure.line = dep.line;
	departure.direction = dep.direction;
	departure.minute = dep.minute;
	departure.earliest_departure = dep.earliest_departure;
	departure.latest_departure = dep.latest_departure;
	departure.weekday = dep.weekday;
	departure.valid_at_time = dep.valid_at_time;
	
	return departure;
}

-(NSString *)description {
	return [NSString stringWithFormat:@"station: %@, line: %@, direction: %@, minute: %d, earliest_departure: %d, latest_departure: %d, valid_at_time: %d", station, line, direction, minute, earliest_departure, latest_departure, valid_at_time];
}

-(BOOL)isValidForHour:(int)hour {
	int combined_time = hour * 100 + self.minute;
	
	if (self.earliest_departure <= combined_time && self.latest_departure >= combined_time) {
		valid_at_time = combined_time;
		return YES;
	} else {
		return NO;
	}
}

@end
